package compositePattern;

import jdk.nashorn.internal.objects.annotations.Getter;

import java.util.ArrayList;
import java.util.List;

//经理：组合节点类，拥有子节点（员工）
public class Manager implements Employee {
    private String name;
    private String position;
    private List<Employee> subordinates;

    public Manager(String name, String position) {
        this.name = name;
        this.position = position;
        this.subordinates = new ArrayList<>();
    }

    //添加子节点
    public void add(Employee employee) {
        subordinates.add(employee);
    }

    //移除子节点
    public void remove(Employee employee) {
        subordinates.remove(employee);
    }

    // 获取下属
    public List<Employee> getSubordinates() {
        return subordinates;
    }


    @Override
    public void showDetails() {
        System.out.println("Manager: " + name + ", Position: " + position);
        for (Employee subordinate : subordinates) {
            subordinate.showDetails();
        }
    }
}
